/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    overflow: hidden;
}

/* Container adapts to iframe or full window */
.container {
    width: 100%;
    height: 450px; /* Default iframe height */
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Full window mode */
@media (min-height: 500px) {
    .container {
        height: 90vh;
    }
}

/* Header tooltip for space efficiency */
.header-tooltip {
    position: absolute;
    top: 5px;
    right: 10px;
    z-index: 1000;
    cursor: pointer;
    font-size: 16px;
    color: #666;
    transition: color 0.3s ease;
}

.header-tooltip:hover {
    color: #007bff;
}

.header-tooltip .tooltip-text {
    visibility: hidden;
    width: 300px;
    background-color: rgba(0, 0, 0, 0.9);
    color: white;
    text-align: center;
    border-radius: 6px;
    padding: 8px;
    position: absolute;
    z-index: 1001;
    bottom: 125%;
    right: 0;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.3s;
}

.header-tooltip:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}

/* Main content layout */
.main-content {
    display: flex;
    height: 100%;
    gap: 8px;
    padding: 25px 8px 8px 8px;
}

/* Left panel - 25% width */
.left-panel {
    width: 25%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sketch-gallery {
    background: white;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    flex: 1;
}

.gallery-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 14px;
    color: #333;
}

.gallery-controls {
    display: flex;
    gap: 4px;
}

.sketch-thumbnails {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    max-height: 120px;
    overflow-y: auto;
}

.thumbnail {
    aspect-ratio: 1;
    background: #f8f9fa;
    border: 2px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    text-align: center;
    padding: 4px;
}

.thumbnail:hover {
    border-color: #007bff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,123,255,0.3);
}

.thumbnail.active {
    border-color: #28a745;
    background: #e8f5e8;
}

.stroke-reference {
    background: white;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    flex: 1;
}

.reference-header {
    font-weight: 600;
    font-size: 14px;
    color: #333;
    margin-bottom: 8px;
}

.stroke-types {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 120px;
    overflow-y: auto;
}

.stroke-btn {
    padding: 6px 8px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    text-align: left;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.stroke-btn:hover {
    background: #e9ecef;
    border-color: #007bff;
}

.stroke-btn.selected {
    background: #007bff;
    color: white;
    border-color: #0056b3;
}

/* Center panel - 50% width */
.center-panel {
    width: 50%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sketch-display {
    background: white;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    flex: 1;
}

.display-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.btn-control {
    padding: 4px 8px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.3s ease;
    min-width: 32px;
    height: 28px;
}

.btn-control:hover {
    background: #e9ecef;
    border-color: #007bff;
}

.btn-control.active {
    background: #007bff;
    color: white;
    border-color: #0056b3;
}

.sketch-title {
    font-weight: 600;
    color: #333;
    font-size: 14px;
    flex: 1;
    text-align: center;
}

.sketch-canvas {
    position: relative;
    width: 100%;
    height: calc(100% - 40px);
    border: 1px solid #dee2e6;
    border-radius: 4px;
    overflow: hidden;
    background: #fafafa;
}

#mainCanvas {
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

.interaction-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.highlight-area {
    position: absolute;
    border: 2px solid #007bff;
    background: rgba(0, 123, 255, 0.1);
    border-radius: 4px;
    pointer-events: auto;
    cursor: pointer;
    transition: all 0.3s ease;
}

.highlight-area:hover {
    background: rgba(0, 123, 255, 0.2);
    border-color: #0056b3;
}

.comparison-toggle {
    text-align: center;
}

.btn-toggle {
    padding: 6px 16px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.3s ease;
    height: 32px;
}

.btn-toggle:hover {
    background: #218838;
    transform: translateY(-1px);
}

/* Right panel - 25% width */
.right-panel {
    width: 25%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.identification-mode {
    background: white;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.mode-header {
    font-weight: 600;
    font-size: 14px;
    color: #333;
    margin-bottom: 8px;
}

.selected-stroke {
    padding: 8px;
    background: #f8f9fa;
    border-radius: 4px;
    margin-bottom: 8px;
    font-size: 12px;
    text-align: center;
    border: 1px solid #dee2e6;
}

.confidence-slider {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.confidence-slider label {
    font-size: 11px;
    color: #666;
}

.confidence-slider input {
    width: 100%;
}

.confidence-slider span {
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: #007bff;
}

.results-section {
    background: white;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    flex: 1;
    display: flex;
    flex-direction: column;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 14px;
    color: #333;
}

.results-table {
    flex: 1;
    display: flex;
    flex-direction: column;
    font-size: 10px;
}

.table-header {
    display: grid;
    grid-template-columns: 1fr 1fr 0.7fr 1fr;
    gap: 4px;
    padding: 4px;
    background: #f8f9fa;
    border-radius: 4px;
    font-weight: 600;
    margin-bottom: 4px;
}

.table-body {
    flex: 1;
    overflow-y: auto;
    max-height: 100px;
}

.table-row {
    display: grid;
    grid-template-columns: 1fr 1fr 0.7fr 1fr;
    gap: 4px;
    padding: 4px;
    border-bottom: 1px solid #eee;
    align-items: center;
}

.table-row:hover {
    background: #f8f9fa;
}

.feedback-section {
    background: white;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    min-height: 60px;
}

.feedback-content {
    font-size: 12px;
    color: #666;
    line-height: 1.4;
}

.feedback-content.success {
    color: #28a745;
}

.feedback-content.error {
    color: #dc3545;
}

/* Button styles */
.btn-small {
    padding: 3px 8px;
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 10px;
    transition: all 0.3s ease;
    height: 24px;
    white-space: nowrap;
}

.btn-small:hover {
    background: #5a6268;
    transform: translateY(-1px);
}

/* Tooltip */
.tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    max-width: 200px;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.tooltip.show {
    opacity: 1;
}

/* Hint modal */
.hint-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.hint-modal.show {
    display: flex;
}

.hint-content {
    background: white;
    border-radius: 8px;
    padding: 20px;
    max-width: 400px;
    max-height: 300px;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.hint-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    font-weight: 600;
    color: #333;
}

.close-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    color: #333;
}

.hint-item {
    margin-bottom: 12px;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 4px;
    border-left: 3px solid #007bff;
}

.hint-item h4 {
    font-size: 14px;
    margin-bottom: 4px;
    color: #333;
}

.hint-item p {
    font-size: 12px;
    color: #666;
    line-height: 1.4;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
        gap: 6px;
        padding: 20px 6px 6px 6px;
    }
    
    .left-panel,
    .center-panel,
    .right-panel {
        width: 100%;
    }
    
    .center-panel {
        order: -1;
        height: 200px;
    }
    
    .sketch-thumbnails {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .table-header,
    .table-row {
        font-size: 9px;
    }
    
    .btn-control,
    .btn-small {
        min-height: 32px;
        font-size: 11px;
    }
}

/* Touch-friendly interactions */
@media (hover: none) {
    .thumbnail,
    .stroke-btn,
    .btn-control,
    .btn-small,
    .btn-toggle {
        min-height: 44px;
    }
    
    .highlight-area {
        min-width: 44px;
        min-height: 44px;
    }
}